package com.cong.juc;

import com.cong.juc.enums.CountryEnum;

import java.util.Objects;
import java.util.concurrent.CountDownLatch;

/**
 * CountDownLatch示例
 *
 * @author cong
 * <p>
 * created on 2021/3/31 上午10:00
 */
public class CountDownLatchDemo {
    /**
     * 都over以后才可以离开
     *
     * @param args
     */
    public static void main(String[] args) {
        try {
            CountDownLatch latch = new CountDownLatch(6);
            for (int i = 1; i <= 6; i++) {
                new Thread(() -> {
                    System.out.println(Thread.currentThread().getName() + "\t 国，被灭");
                    latch.countDown();
                }, Objects.requireNonNull(CountryEnum.forEachCountryEnum(i)).getName()).start();
            }
            latch.await();
            System.out.println(Thread.currentThread().getName() + "\t 秦完成统一");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
